package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SchSchedule;
import com.ruoyi.system.service.ISchScheduleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排庭主Controller
 * 
 * @author ruoyi
 * @date 2020-11-03
 */
@Controller
@RequestMapping("/system/schedule")
public class SchScheduleController extends BaseController
{
    private String prefix = "system/schedule";

    @Autowired
    private ISchScheduleService schScheduleService;

    @RequiresPermissions("system:schedule:view")
    @GetMapping()
    public String schedule()
    {
        return prefix + "/schedule";
    }

    /**
     * 查询排庭主列表
     */
    @RequiresPermissions("system:schedule:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SchSchedule schSchedule)
    {
        startPage();
        List<SchSchedule> list = schScheduleService.selectSchScheduleList(schSchedule);
        return getDataTable(list);
    }

    /**
     * 导出排庭主列表
     */
    @RequiresPermissions("system:schedule:export")
    @Log(title = "排庭主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SchSchedule schSchedule)
    {
        List<SchSchedule> list = schScheduleService.selectSchScheduleList(schSchedule);
        ExcelUtil<SchSchedule> util = new ExcelUtil<SchSchedule>(SchSchedule.class);
        return util.exportExcel(list, "schedule");
    }

    /**
     * 新增排庭主
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存排庭主
     */
    @RequiresPermissions("system:schedule:add")
    @Log(title = "排庭主", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SchSchedule schSchedule)
    {
        return toAjax(schScheduleService.insertSchSchedule(schSchedule));
    }

    /**
     * 修改排庭主
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SchSchedule schSchedule = schScheduleService.selectSchScheduleById(id);
        mmap.put("schSchedule", schSchedule);
        return prefix + "/edit";
    }

    /**
     * 修改保存排庭主
     */
    @RequiresPermissions("system:schedule:edit")
    @Log(title = "排庭主", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SchSchedule schSchedule)
    {
        return toAjax(schScheduleService.updateSchSchedule(schSchedule));
    }

    /**
     * 删除排庭主
     */
    @RequiresPermissions("system:schedule:remove")
    @Log(title = "排庭主", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(schScheduleService.deleteSchScheduleByIds(ids));
    }
}
